# Copyright 2019 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("//build_tools/bazel:build_defs.oss.bzl", "iree_compiler_cc_library")

package(
    default_visibility = ["//visibility:public"],
    features = ["layering_check"],
    licenses = ["notice"],  # Apache 2.0
)

bool_flag(
    name = "IREE_EMBEDDED_RELEASE_INFO",
    build_setting_default = False,
)

config_setting(
    name = "embedding_enabled",
    flag_values = {
        ":IREE_EMBEDDED_RELEASE_INFO": "True",
    },
)

iree_compiler_cc_library(
    name = "init_iree_passes_and_dialects",
    hdrs = [
        "init_iree_dialects.h",
        "init_iree_passes.h",
    ],
    deps = [
        "//compiler/src/iree/compiler/Bindings/Native/Transforms",
        "//compiler/src/iree/compiler/Bindings/TFLite/Transforms",
        "//compiler/src/iree/compiler/Codegen/Dialect/CPU/IR:IREECPUDialect",
        "//compiler/src/iree/compiler/Codegen/Dialect/Codegen/IR:IREECodegenDialect",
        "//compiler/src/iree/compiler/Codegen/Dialect/GPU/IR:IREEGPUDialect",
        "//compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR:IREEVectorExtDialect",
        "//compiler/src/iree/compiler/Codegen/Interfaces",
        "//compiler/src/iree/compiler/ConstEval",
        "//compiler/src/iree/compiler/Dialect/Encoding/IR",
        "//compiler/src/iree/compiler/Dialect/Flow/IR",
        "//compiler/src/iree/compiler/Dialect/Flow/Transforms",
        "//compiler/src/iree/compiler/Dialect/HAL/IR:HALDialect",
        "//compiler/src/iree/compiler/Dialect/HAL/Transforms",
        "//compiler/src/iree/compiler/Dialect/LinalgExt/IR",
        "//compiler/src/iree/compiler/Dialect/LinalgExt/Transforms",
        "//compiler/src/iree/compiler/Dialect/Stream/IR",
        "//compiler/src/iree/compiler/Dialect/Stream/Transforms",
        "//compiler/src/iree/compiler/Dialect/Util/IR",
        "//compiler/src/iree/compiler/Dialect/Util/TransformOps",
        "//compiler/src/iree/compiler/Dialect/Util/Transforms",
        "//compiler/src/iree/compiler/Dialect/VM/Analysis",
        "//compiler/src/iree/compiler/Dialect/VM/Conversion/VMToEmitC",
        "//compiler/src/iree/compiler/Dialect/VM/IR",
        "//compiler/src/iree/compiler/Dialect/VM/Transforms",
        "//compiler/src/iree/compiler/Dialect/VMVX/IR:VMVXDialect",
        "//compiler/src/iree/compiler/Dialect/VMVX/Transforms",
        "//compiler/src/iree/compiler/DispatchCreation",
        "//compiler/src/iree/compiler/ExternalInterfaces:ExternalModels",
        "//compiler/src/iree/compiler/GlobalOptimization/Interfaces",
        "//compiler/src/iree/compiler/InputConversion/Common",
        "//compiler/src/iree/compiler/Modules/HAL/Inline/IR:HALInlineDialect",
        "//compiler/src/iree/compiler/Modules/HAL/Inline/Transforms",
        "//compiler/src/iree/compiler/Modules/HAL/Loader/IR:HALLoaderDialect",
        "//compiler/src/iree/compiler/Modules/HAL/Loader/Transforms",
        "//compiler/src/iree/compiler/Modules/IO/Parameters/IR:IOParametersDialect",
        "//compiler/src/iree/compiler/Modules/IO/Parameters/Transforms",
        "//compiler/src/iree/compiler/Pipelines",
        "//compiler/src/iree/compiler/Preprocessing:Passes",
        "//compiler/src/iree/compiler/Preprocessing/TransformExtensions:PreprocessingExtensions",
        "//llvm-external-projects/iree-dialects:IREELinalgTransformDialect",
        "//llvm-external-projects/iree-dialects:IREELinalgTransformDialectPasses",
        "@llvm-project//mlir:IR",
    ],
)

iree_compiler_cc_library(
    name = "init_mlir_passes_and_dialects",
    hdrs = [
        "init_mlir_dialects.h",
        "init_mlir_passes.h",
    ],
    deps = [
        "//compiler/src/iree/compiler/Dialect/VM/Target:init_targets",
        "@llvm-project//mlir:AffineDialect",
        "@llvm-project//mlir:AffineTransforms",
        "@llvm-project//mlir:ArmNeon2dToIntr",
        "@llvm-project//mlir:ArmNeonDialect",
        "@llvm-project//mlir:ArmSVEDialect",
        "@llvm-project//mlir:ArmSMEDialect",
        "@llvm-project//mlir:BufferizationDialect",
        "@llvm-project//mlir:ComplexDialect",
        "@llvm-project//mlir:ControlFlowDialect",
        "@llvm-project//mlir:ControlFlowTransforms",
        "@llvm-project//mlir:ConversionPasses",
        "@llvm-project//mlir:EmitCDialect",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:FuncExtensions",
        "@llvm-project//mlir:FuncToSPIRV",
        "@llvm-project//mlir:FunctionInterfaces",
        "@llvm-project//mlir:GPUDialect",
        "@llvm-project//mlir:GPUToSPIRV",
        "@llvm-project//mlir:GPUTransforms",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:LLVMDialect",
        "@llvm-project//mlir:LLVMIRTransforms",
        "@llvm-project//mlir:LinalgDialect",
        "@llvm-project//mlir:LinalgPassIncGen",
        "@llvm-project//mlir:LinalgTransforms",
        "@llvm-project//mlir:MLProgramDialect",
        "@llvm-project//mlir:MathDialect",
        "@llvm-project//mlir:MemRefDialect",
        "@llvm-project//mlir:QuantOps",
        "@llvm-project//mlir:ROCDLDialect",
        "@llvm-project//mlir:SCFDialect",
        "@llvm-project//mlir:SCFToGPU",
        "@llvm-project//mlir:SCFTransforms",
        "@llvm-project//mlir:SPIRVDialect",
        "@llvm-project//mlir:SPIRVTransforms",
        "@llvm-project//mlir:ShapeDialect",
        "@llvm-project//mlir:TensorInferTypeOpInterfaceImpl",
        "@llvm-project//mlir:TransformDialect",
        "@llvm-project//mlir:Transforms",
        "@llvm-project//mlir:VectorDialect",

        # TransformExtensions
        "@llvm-project//mlir:AffineTransformOps",
        "@llvm-project//mlir:BufferizationTransformOps",
        "@llvm-project//mlir:FuncTransformOps",
        "@llvm-project//mlir:GPUTransformOps",
        "@llvm-project//mlir:LinalgTransformOps",
        "@llvm-project//mlir:MemRefTransformOps",
        "@llvm-project//mlir:SCFTransformOps",
        "@llvm-project//mlir:TensorTransformOps",
        "@llvm-project//mlir:TransformLoopExtension",
        "@llvm-project//mlir:VectorTransformOps",
    ],
)

iree_compiler_cc_library(
    name = "init_passes_and_dialects",
    hdrs = [
        "init_dialects.h",
        "init_passes.h",
    ],
    deps = [
        ":init_compiler_modules",
        ":init_iree_passes_and_dialects",
        ":init_mlir_passes_and_dialects",
        "//compiler/src/iree/compiler/Codegen",
    ],
)

iree_compiler_cc_library(
    name = "init_compiler_modules",
    hdrs = ["init_compiler_modules.h"],
    deps = [
        "//compiler/src/iree/compiler/Modules/Check/IR:CheckDialect",
    ],
)

config_setting(
    name = "cuda_enabled",
    flag_values = {
        "@iree_cuda//:enabled": "True",
    },
)

iree_compiler_cc_library(
    name = "init_llvmir_translations",
    hdrs = [
        "init_llvmir_translations.h",
    ],
    deps = [
        "@llvm-project//mlir:ArmNeonToLLVMIRTranslation",
        "@llvm-project//mlir:ToLLVMIRTranslation",
    ],
)

iree_compiler_cc_library(
    name = "iree_compile_lib",
    srcs = [
        "iree_compile_lib.cc",
    ],
    hdrs = ["iree_compile_lib.h"],
    deps = [
        "//compiler/bindings/c:headers",
        "//compiler/src/iree/compiler/API/Internal:CompilerDriver",
        "//compiler/src/iree/compiler/Pipelines",
        "@llvm-project//llvm:Support",
    ],
)

iree_compiler_cc_library(
    name = "version",
    srcs = ["version.cc"],
    hdrs = ["version.h"],
    local_defines = select({
        ":embedding_enabled": [
            "IREE_RELEASE_REVISION=\\\"$(IREE_RELEASE_REVISION)\\\"",
            "IREE_RELEASE_VERSION=\\\"$(IREE_RELEASE_VERSION)\\\"",
        ],
        "//conditions:default": [],
    }),
)
